package org.gruposp2p.proyectokarma.domain;

import org.hibernate.search.annotations.DocumentId;
import javax.persistence.GeneratedValue;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import static javax.persistence.GenerationType.IDENTITY;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.Resolution;

@Indexed
@Entity
@Table(name="Document")
public class Document implements java.io.Serializable {

	 private static final long serialVersionUID = 1L;
	 
	 @Id @GeneratedValue(strategy=IDENTITY)
     @Column(name="id", unique=true, nullable=false)
     @DocumentId
     private Long id;
     @ManyToOne(fetch=FetchType.LAZY)
     @JoinColumn(name="peerId", nullable=false)
     private Peer peer;
     @ManyToOne(fetch=FetchType.LAZY)
     @JoinColumn(name="karmaParameterId")
     private KarmaParameter karmaParameter;
     @Column(name="name", nullable=false)
     @Field
     private String name;
     @DateBridge( resolution = Resolution.DAY )
     @Temporal(TemporalType.TIMESTAMP)
     @Column(name="dateCreated", length=23)
     private Date dateCreated;
     @DateBridge( resolution = Resolution.DAY )
     @Temporal(TemporalType.TIMESTAMP)
     @Column(name="pollingValidTo", length=23)
     private Date pollingValidTo;
     @Temporal(TemporalType.TIMESTAMP)
     @Column(name="lastUpdated", length=23)
     private Date lastUpdated;
     @Column(name="content", nullable=false, length=60000)
     @Field
     private String content;
     @Column(name="polling", nullable=false)
     private Boolean polling;
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="document")
     private Set<Vote> votes = new HashSet<Vote>(0);
     @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="document")
     private Set<DocumentTag> documentTags = new HashSet<DocumentTag>(0);

     public Document() { }
	
     public Document(Long id, Peer peer, KarmaParameter karmaParameter,
            String name, Date dateCreated, Date lastUpdated, String content) {
        this.id = id;
        this.peer = peer;
        this.karmaParameter = karmaParameter;
        this.name = name;
        this.dateCreated = dateCreated;
        this.lastUpdated = lastUpdated;
        this.content = content;
     }
   
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    public Peer getPeer() {
        return this.peer;
    }
    
    public void setPeer(Peer peer) {
        this.peer = peer;
    }

    public KarmaParameter getKarmaParameter() {
        return this.karmaParameter;
    }
    
    public void setKarmaParameter(KarmaParameter karmaParameter) {
        this.karmaParameter = karmaParameter;
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }
    
    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getLastUpdated() {
        return this.lastUpdated;
    }
    
    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }
    
    public String getContent() {
        return this.content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }

    public Set<Vote> getVotes() {
        return this.votes;
    }
    
    public void setVotes(Set<Vote> votes) {
        this.votes = votes;
    }

    public Set<DocumentTag> getDocumentTags() {
        return this.documentTags;
    }
    
    public void setDocumentTags(Set<DocumentTag> documentTags) {
        this.documentTags = documentTags;
    }

	public void setPolling(Boolean polling) {
		this.polling = polling;
	}

	public Boolean getPolling() {
		return polling;
	}

	public void setPollingValidTo(Date pollingValidTo) {
		this.pollingValidTo = pollingValidTo;
	}

	public Date getPollingValidTo() {
		return pollingValidTo;
	}

}


